package com.cykj.shop.controller;

import com.cykj.common.core.domain.R;
import com.cykj.common.core.web.domain.AjaxResult;
import com.cykj.shop.domain.vo.BusinessVo;
import com.cykj.shop.service.BusinessService;

import com.cykj.system.api.RemoteFileService;
import com.cykj.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author 叶佳伟
 * @date 2025/8/18
 * @description 功能描述: 商家控制器
 */

@RestController
@RequestMapping("business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;
    @Resource
    private RemoteFileService remoteFileService;

    //商家注册账号
    @PostMapping("register")
    public AjaxResult register(@RequestBody BusinessVo businessVo){
        return businessService.register(businessVo);
    }

    //商家修改密码
    @PutMapping("updatePassword")
    public AjaxResult updatePassword(@RequestBody BusinessVo businessVo){
        return businessService.updatePassword(businessVo);
    }

    //商家修改头像
    @PutMapping("updateAvatar")
    public AjaxResult updateAvatar(@RequestParam Integer id,
                                   @RequestParam MultipartFile avatar){
        //文件上传
        R<SysFile> avatarFile = remoteFileService.upload(avatar);
        //获取图片Url
        String avatarUrl = avatarFile.getData().getUrl();

        return businessService.updateAvatar(id,avatarUrl);
    }

}
